package com.wenhuitec.sysui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TableRow;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.wenhuitec.sysui.R;
import com.wenhuitec.sysui.entity.FoodSkuModel;

import java.util.List;

public class ShowFoodSkuAdapter extends RecyclerView.Adapter<ShowFoodSkuAdapter.MyViewHolder> {

    private LayoutInflater inflater;
    private Context mContext;
    private List<FoodSkuModel> mFoodSkuModelList;

    public ShowFoodSkuAdapter(Context context, List<FoodSkuModel> foodSkuModelList) {
        inflater = LayoutInflater.from(context);
        mContext = context;
        mFoodSkuModelList = foodSkuModelList;

    }

    //创建每一行的View 用RecyclerView.ViewHolder包装
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = inflater.inflate(R.layout.item_show_sku, null);
        return new MyViewHolder(itemView);
    }


    //给每一行View填充数据
    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.nameTv.setText(mFoodSkuModelList.get(position).getName());
        holder.priceTv.setText("￥" + mFoodSkuModelList.get(position).getPrice() + "元");
        holder.packingChargeTv.setText("包装费:" + mFoodSkuModelList.get(position).getPachagePrice() + "元");
    }

    @Override
    public int getItemCount() {
        return mFoodSkuModelList.size();
    }


    class MyViewHolder extends RecyclerView.ViewHolder {
        TextView nameTv;
        TextView priceTv;
        TextView packingChargeTv;

        public MyViewHolder(View itemView) {
            super(itemView);
            nameTv = (TextView) itemView.findViewById(R.id.nameTv);
            priceTv = (TextView) itemView.findViewById(R.id.priceTv);
            packingChargeTv = (TextView) itemView.findViewById(R.id.packingChargeTv);
        }
    }

}
